{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#  Layer weight sharing\n",
    "Jab 1 layer share ya reuse kerte hai Functional Api mai to woh layers ke sath us wakt ke weights bhe atay hai(use hote hai).\n",
    "\n",
    "For Eg: Consider kare 1 model hai jiske 2 input sentences hai, joke identical ( same, dublicate data hai) ya reformulation ( milte julte, same meaning ) hai. aisa model deduplicating natural-language queries in a dialog system ka ho sakta hai, jismai same questions bar bar user different tareke se poch raha ho.\n",
    "\n",
    "Aise model ko hum single lstm se guzar sakte hai, jiske weights both input se simultaneously learn karega, aise lstm ko hum Siamese LSTM model or a shared LSTM kehte hai. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from keras import layers\n",
    "from keras import Input\n",
    "from keras.models import Model\n",
    "\n",
    "lstm = layers.LSTM(32)                # 1 Lstm layer bnai\n",
    "\n",
    "left_input = Input(shape=(None, 128)) # 1st input\n",
    "left_output = lstm(left_input)        # same upper wala Lstm dia\n",
    "\n",
    "right_input = Input(shape=(None, 128)) # 2nd input\n",
    "right_output = lstm(right_input)       # same upper wala Lstm dia\n",
    "\n",
    "merged = layers.concatenate([left_output, right_output], axis=-1) # dono input ko murged kerdia\n",
    "\n",
    "predictions = layers.Dense(1, activation='sigmoid')(merged) # yaha input merged wala dia\n",
    "\n",
    "# 2 input 1 output model\n",
    "model = Model([left_input, right_input], predictions)\n",
    "\n",
    "# training start kerde\n",
    "model.fit([left_data, right_data], targets)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
